﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace androidpost
{
    public partial class FormLog : Form
    {
        Boolean isLoadLog = true;
        Boolean isLoadLog1 = true;
        public FormLog()
        {
            InitializeComponent();
        }

        private void FormLog_Load(object sender, EventArgs e)
        {
            Thread threadlog = new Thread(readLog);
            threadlog.Start();
        }

       void readLog()
        {
            do
            {
                Thread.Sleep(Utils.Constant.REQUEST_TIMEOUT);
                string text = "";
                try
                {
                     text = File.ReadAllText("log.txt");
                }
                catch (Exception)
                {
                    
                    
                }

                if (isLoadLog1)
                {
                    Utils1.SynchronizedInvoke(tbLog, delegate() { tbLog.Text = text; });

                    if (tbLog.Text.Length > 0)
                    {
                        Utils1.SynchronizedInvoke(tbLog, delegate()
                        {
                            tbLog.SelectionStart = tbLog.Text.Length;
                            tbLog.ScrollToCaret();
                        });

                    }
                }
               
               
            } while (isLoadLog);
           

        }

       private void btnClearLog_Click(object sender, EventArgs e)
       {
           Utils1.Clearlog();
           tbLog.Text = "";

       }

       private void FormLog_FormClosed(object sender, FormClosedEventArgs e)
       {
           isLoadLog = false;
       }

       private void btnPause_Click(object sender, EventArgs e)
       {
           btnPause.Text = "Continute";
           if ( isLoadLog1 == false) //pause
           {
               btnPause.Text = "Pause";
                isLoadLog1 = true;
           }
           else isLoadLog1 = false;
       }

    }
}
